package com.ruoyi.system.service;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

public class RandomNameGenerator {

    // 用于生成随机名称的字符集
    private static final String CHARACTERS = "abcdefghijklmnopqrstuvwxyz";

    // 用于存储已经生成的名称
    private Set<String> generatedNames;

    // 随机数生成器
    private Random random;

    // 构造函数
    public RandomNameGenerator() {
        this.generatedNames = new HashSet<>();
        this.random = new Random();
    }

    // 生成一个随机名称
    private String generateRandomName() {
        StringBuilder builder = new StringBuilder();
        int length = random.nextInt(8) + 3; // 名称长度在3到10之间
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(CHARACTERS.length());
            builder.append(CHARACTERS.charAt(index));
        }
        return builder.toString();
    }

    // 生成指定数量的随机名称
    public void generateNames(int count) {
        while (generatedNames.size() < count) {
            String name = generateRandomName();
            if (!generatedNames.contains(name)) {
                generatedNames.add(name);
            }
        }
    }

    // 获取生成的名称列表
    public Set<String> getGeneratedNames() {
        return generatedNames;
    }

    // 测试方法
    public static void main(String[] args) {
        RandomNameGenerator generator = new RandomNameGenerator();
        generator.generateNames(1000000);
        System.out.println(generator.getGeneratedNames().size()); // 输出1000000，表示没有重复的名称
    }
}